<?php
$file_name = $argv[1];
$submit_id = $argv[2];
$branch_id = $argv[3];
file_put_contents ('bg.txt', $file_name . ' | ' . $submit_id . ' | ' . $branch_id);
$source = fopen('/usr/local/apache/htdocs/CG3002/uploads/transactions/' . $file_name, 'r');

$con=mysql_connect("CG3002-06-z.comp.nus.edu.sg","root","root") or die ('Error Cannot Connect to MySQL');
@mysql_select_db('cg3002_hq') or die( "Unable to select database");

while (($data = fgetcsv($source, 100000, ",")) !== FALSE)
{
	$date = DateTime::createFromFormat('d/m/Y H:i:s', $data[6]);
	$newformat = $date->format('Y-m-d H:i:s');
	mysql_query("INSERT INTO `transaction_detail`
			(`submit_id`, `transaction_id`, `branch_id`, `cashier_id`, `item_barcode`, `transaction_quantity`, `total_price`, `transaction_date`)
			VALUES (". $submit_id .", '". $data[0] ."', ". $branch_id .", '". $data[1] ."', '". $data[3] ."', '". $data[4] ."', '". $data[5] ."', '". $newformat ."')");
	//$this->transaction_model->add_detail($submit_id, $data[0],$branch_id,$data[1],$data[3],$data[4],$data[5],$data[6]);
}
fclose($source);
mysql_close($con);

exit(0);